<template>
  <div class="elm-edit">
    <elm-page-bb>
      <el-form ref="model" :model="model" size="small" label-width="120px">
        <el-form-item label="名称" prop="name" v-if="!is_turn">
          <el-input v-model="model.name"></el-input>
        </el-form-item>
        <elm-row>
          <el-form-item label="商机编号" prop="sys_code_key">
            <el-input v-model="model.sys_code_key" :disabled="true" placeholder="自动生成无需填写"></el-input>
          </el-form-item>
          <el-form-item label="预计金额" prop="yjje"  :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model="model.yjje">
              <template slot="append"><div style="width: 25px;text-align: center;">万元</div></template>
            </el-input>
          </el-form-item>
        </elm-row>
        <elm-row v-if="!is_turn">
          <el-form-item label="状态" prop="zt">
            <elm-code dict_type="crm_opportunity_zt" v-model="model.zt"></elm-code>
          </el-form-item>
          <el-form-item label="阶段" prop="jd">
            <elm-code dict_type="crm_opportunity_jd" v-model="model.jd"></elm-code>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="预计关闭时间" prop="yjgbrq">
            <el-date-picker v-model="model.yjgbrq" type="datetime"   value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="登记时间" prop="djrq">
            <el-date-picker v-model="model.djrq" type="datetime"   value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%">
            </el-date-picker>
          </el-form-item>
        </elm-row>
        <elm-row v-if="!is_turn">
          <el-form-item label="跟进人" prop="fzxs">
            <elm-ei v-model="model.fzxs" disabled></elm-ei>
          </el-form-item>
          <el-form-item label="客户" prop="kh_name">
            <elm-cus v-model="model.kh_name"></elm-cus>
          </el-form-item>
        </elm-row>
        <elm-row v-if="!is_turn">
          <el-form-item label="商机来源" prop="ly">
            <el-input v-model="model.ly"></el-input>
          </el-form-item>
          <el-form-item label="类型" prop="lx">
            <elm-code dict_type="crm_opportunity_lx" v-model="model.lx"></elm-code>
          </el-form-item>
        </elm-row>
        <elm-row>
          <el-form-item label="成功概率" prop="gl"  :rules="[{trigger: 'blur' ,validator: validateNumber}]">
            <el-input v-model="model.gl">
              <template slot="append"><div style="width: 25px;text-align: center;">%</div></template>
            </el-input>
          </el-form-item>
          <el-form-item label="风险" prop="fx">
            <elm-code dict_type="crm_opportunity_fx" v-model="model.fx"></elm-code>
          </el-form-item>
        </elm-row>
        <el-form-item label="资料">
          <elm-upload module_name="biz_crm_opportunity_file" :rel_id="model.id" :multiple="true" :limit="10"  list-type="picture" tip=" "></elm-upload>
        </el-form-item>
        <el-form-item label="备注" prop="remark" v-if="!is_turn">
          <el-input type="textarea" :rows="2" v-model="model.remark"></el-input>
        </el-form-item>
      </el-form>
      <el-card style="min-height: 140px;"  shadow="hover" v-if="!is_turn">
        <div slot="header">
          <span>联系人信息</span>
        </div>
        <el-form ref="model" :model="model" size="small" label-width="120px">
          <elm-row>
            <el-form-item label="姓名" prop="lxr_xm">
              <el-input v-model="model.lxr_xm"></el-input>
            </el-form-item>
            <el-form-item label="职务" prop="lxr_zw">
              <el-input v-model="model.lxr_zw"></el-input>
            </el-form-item>
          </elm-row>
          <elm-row>
            <el-form-item label="电话" prop="lxr_dh">
              <el-input v-model="model.lxr_dh"></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="lxr_email">
              <el-input v-model="model.lxr_email"></el-input>
            </el-form-item>
          </elm-row>
        </el-form>
      </el-card>
      <template #bottom>
        <el-button type="success" size="small" @click="submit">立即保存</el-button>
        <el-button size="small" @click="close">取消</el-button>
      </template>
    </elm-page-bb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      is_turn:elm.dialog.request.is_turn,
      model: {id: elm.newGuid(),fzxs:null},
    }
  },
  async created() {
    this.model.fzxs= await this.get_user_ei();
  },
  methods: {

    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/my/business/UpsertOppo', this.model);
      if (res == true) {
        this.v('保存成功。')
        this.close();
        this.request.callVue.tablebinding();
      }
      else {
        this.error('保存失败，请稍后尝试。');
      }
    },
    async get_user_ei(){
      var res = await elm.post('/system/login/GetUserEi');
      //console.log(res);
      if(res.length>0)
        return res[0].emp_code;
      else
        return "";
    },
  }
}
</script>